<?php include $this->header();?>
<?php if(false) {?>
<link rel="stylesheet" rev="stylesheet" href="../../../images/admincp/style.css" type="text/css" media="all" />
<?php }?>
<a href="<?=UE_Url::make('product/admin/add/filter/cat_id/'.(isset($_GET['cat_id']) ? $_GET['cat_id'] : ''))?>" class="btn-r-top">添加商品</a>

<div class="pd mt bd search-bar">
  <form method="get" enctype="application/x-www-form-urlencoded" target="_self">
      <select id="cat_id" onchange="window.location='index.php?app=product&ctl=admin&act=list<?php if(isset($_GET['status'])){?>&status=<?=$_GET['status']?><?php }?>&cat_id='+this.value">
          <option value="all">所有商品分类</option>
          <?php foreach($this->_cats as $_cat) :?>
          <option value="<?=$_cat['cat_id']?>" <?php if(isset($_GET['cat_id']) && $_GET['cat_id'] != 'all' && $_GET['cat_id'] == $_cat['cat_id']) {?>selected="selected"<?php }?>><?=$_cat['icon']?><?=$_cat['cat_name']?></option>
          <?php endforeach;?>
      </select>
      <input type="hidden" name="app" value="<?=$app?>" />
      <input type="hidden" name="ctl" value="<?=$ctl?>" />
      <input type="hidden" name="act" value="<?=$act?>" />
      <input type="hidden" name="id" value="<?=$id?>" />
      <input type="text" name="keyword" value="<?php if(empty($_GET['keyword'])){?>请输入关键词<?php } else { print $_GET['keyword'];}?>" onfocus="if(this.value=='请输入关键词') this.value=''" onblur="if(this.value=='') this.value='请输入关键词'" size="30" />
      <input type="submit" value="搜索" class="btn" />
  </form>
  <div class="search-bar-tab">
  <a href="<?=UE_Url::make('product/admin/list/filter/status/all'.(isset($_GET['cat_id'])? '/cat_id/'.$_GET['cat_id'] : ''))?>" <?php if(isset($_GET['status']) && $_GET['status'] == 'all') {?> class="current"<?php }?>>所有</a>
  <a href="<?=UE_Url::make('product/admin/list/filter/status/1'.(isset($_GET['cat_id'])? '/cat_id/'.$_GET['cat_id'] : ''))?>" <?php if(isset($_GET['status']) && $_GET['status'] == 1) {?> class="current"<?php }?>>已发布</a>
  <a href="<?=UE_Url::make('product/admin/list/filter/status/0'.(isset($_GET['cat_id'])? '/cat_id/'.$_GET['cat_id'] : ''))?>" <?php if(isset($_GET['status']) && $_GET['status'] == "0") {?> class="current"<?php }?>>草稿</a>
  <a href="<?=UE_Url::make('product/admin/list/filter/status/-1'.(isset($_GET['cat_id'])? '/cat_id/'.$_GET['cat_id'] : ''))?>" <?php if(isset($_GET['status']) && $_GET['status'] == -1) {?> class="current"<?php }?>>回收站</a>
  </div>
</div>

<form method="post">
  <div class="p1 mt bd bg">
      <table class="list rank" width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr class="th">
          <td align="center" width="40"><input type="checkbox" id="list-check-all" /></td>
          <td align="center" width="40">排序</td>
          <td align="center" width="40">ID</td>
          <td align="left">商品标题</td>
          <td align="center" width="120">分类</td>
          <td align="center" width="126">添加时间</td>
          <td align="center" width="40">发布</td>
          <td width="145" align="center">管理操作</td>
        </tr>
        <?php foreach ($list as $item) {?>
        <tr class="bb">
          <td align="center"><input type="checkbox" class="list-check" name="list-check[<?=$item['product_id']?>]" value="<?=$item['product_id']?>" /></td>
          <td align="center"><input type="text" name="product_order[<?=$item['product_id']?>]" value="<?=$item['product_order']?>" size="3" style="text-align:center;" /></td>
          <td align="center"><?=$item['product_id']?></td>
          <td align="left" onmouseover="$('#item-thumb-<?=$item['product_id']?>').show();" onmouseout="$('.item-thumb').hide()">
            <div style="position:relative;">
              <a href="<?=UE_Url::make('product/show/item/'.$item['product_id'])?>" target="_blank"><?=$item['product_title']?></a>
              <?php if($item['product_cover_rid']):?>
              <!--商品封面图片-->
              <span class="item-thumb" id="item-thumb-<?=$item['product_id']?>"><img src="<?=thumb($item['product_cover_rid'], 100, 100)?>" height="100" width="100" /></span>
              <!--/商品封面图片-->
              <?php endif;?>           
            </div>
          </td>
          <td align="center"><?=empty($item['cat_id']) ? '未分类' : $this->_cats[$item['cat_id']]['cat_name']?></td>
          <td align="center"><?=date('Y-m-d H:i:s', $item['product_dateline'])?></td>
          <td align="center" id="item_status_<?=$item['product_id']?>"><?php if($item['product_status'] == 1) {?><a href="javascript:;" class="green" onclick="setStatus(<?=$item['product_id']?>, 0)">√</a><?php } else {?><a href="javascript:;" class="red" onclick="setStatus(<?=$item['product_id']?>, 0)">×</a><?php } ?></td>
          <td align="center"><a href="<?=UE_Url::make('product/show/item/'.$item['product_id'])?>" target="_blank">查看</a> | <a href="<?=UE_Url::make('product/admin/edit/'.$item['product_id'])?>">编辑</a> | <a href="<?=$item['product_id'] == 3 ? UE_Url::make('product/admin/del/'.$item['product_id']) : UE_Url::make('product/admin/del/'.$item['product_id'])?>" onclick="return confirm('您确定要删除该商品吗?')">删除</a></td>
        </tr>  	
        <?php }?>
      </table>
      <div class="pd"><?=$paging?></div>
  </div>
  
  <div class="mt bd bg pd">
      <div class="ui-widget">
          <table width="100%" cellspacing="0" cellpadding="0" border="0" class="batopt">
              <tr>
                <td width="40" class="font12_title"><div align="center">操作</div></td>
                <td width="860" class="font12_title">
                    <div align="left">
                      <select name="optype" id="optype">
                        <option value="sort" selected="selected">排序</option>
                        <option value="pub">发布</option>
                        <option value="draft">草稿</option>
                        <option value="trash">回收站</option>
                        <option value="del">彻底删除</option>
                      </select>
                      <input type="submit" value="确定" class="btn" name="submit" onclick="if($('#optype').attr('value') == 'del') if(!confirm('确定要删除这些商品吗？')) return false;ajaxStatusStart();">
                     （该操作为批量处理操作，操作前，请在选择列上打钩）           
                   </div>
                </td>
              </tr>
        </table>
    </div>
</div>

</form>
<script type="text/javascript">
//<![CDATA[

$('#list-check-all').click(function(){
	if($(this).attr('checked')) {
		$('.list-check').attr('checked', 'checked');
	} else {
		$('.list-check').removeAttr('checked');
	}
});

function setStatus(id, toStatus) {
	ajaxStatusStart();
	var url = 'index.php?app=product&ctl=admin&act=setStatus&id='+id+'&status='+toStatus;
    $.getJSON(url, function(json){
		ajaxStatusStop();
		if(json.err) {
			alert(json.err);
		} else {
			if(toStatus == 1) {
				$('#item_status_'+id).html('<a href="javascript:;" class="green" onclick="setStatus('+id+', 0)">√</a>');
			} else {
			    $('#item_status_'+id).html('<a href="javascript:;" class="red" onclick="setStatus('+id+', 1)">×</a>');
			}
		}
    });
}
//]]>
</script>
<?php include $this->footer();?>